﻿//Copyright Notice:  ©2009 Microsoft Corporation.  All rights reserved.
using System;
using System.Text;

[assembly: CLSCompliant(true)]

namespace Microsoft.InformationSecurity.CISF.Security.Principal
{
    /// <summary>
    /// Parses a user's name in the form of domain\user.
    /// </summary>
    public class IdentityName
    {
        #region Private Variables
        private string alias = "";
        private string eMailName = "";
        private string name = "";
        private string domain = "";
        private int personId;
        private string fullName = "";
        private string displayName = "";
        private int personnelNumber;

        #endregion

        #region Constructor
        /// <summary>
        /// Parses a user's name in the form of domain\user (domain is optional).
        /// </summary>
        /// <param name="name">A user's name in the form of domain\user (domain is optional).</param>
        public IdentityName(string name)
        {
            this.name = name;
            char[] separator = new char[] { '\\' };

            string[] authUser = this.name.Split(separator, StringSplitOptions.None);

            //If no domain separator is found, assume it's just a name.
            if (authUser.Length == 1)
                this.alias = authUser[0];
            else if (authUser.Length > 1)
            {
                this.domain = authUser[0];
                this.alias = authUser[1];
            }
            else
                throw new ArgumentException("Invalid Identity Name.");
        }

        #endregion

        #region Properties

        #region DisplayName
        /// <summary>
        /// Get's or sets the user's Display Name.
        /// </summary>
        public string DisplayName
        {
            get { return this.displayName; }
            set { this.displayName = value; }
        }

        #endregion

        #region Domain
        /// <summary>
        /// Gets the domain portion of the user's name.
        /// </summary>
        public string Domain
        {
            get { return this.domain; }
        }

        #endregion

        #region EMailName
        public string EMailName
        {
            get { return this.eMailName; }
            set { this.eMailName = value; }
        }

        #endregion

        #region FullName
        /// <summary>
        /// Get's or sets the user's Full Name.
        /// </summary>
        public string FullName
        {
            get { return this.fullName; }
            set { this.fullName = value; }
        }

        #endregion

        #region Name
        /// <summary>
        /// Gets the user's name.
        /// </summary>
        public string Name
        {
            get { return this.name; }
        }

        #endregion

        #region PersonId
        /// <summary>
        /// Get's or sets the user's Full Name.
        /// </summary>
        public int PersonId
        {
            get { return this.personId; }
            set { this.personId = value; }
        }

        #endregion

        #region Alias
        /// <summary>
        /// Gets or sets the sAMAccountName.
        /// </summary>
        public string Alias
        {
            get { return this.alias; }
        }

        #endregion

        #region PersonnelNumber
        /// <summary>
        /// Gets or sets the PersonnelNumber.
        /// </summary>
        public int PersonnelNumber
        {
            get { return this.personnelNumber; }
            set { this.personnelNumber = value; }
        }

        #endregion

        #endregion

    }
}
